package com.kadapatha.web.base;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;

import org.apache.commons.lang.StringEscapeUtils;

public class BaseForm {

	protected boolean error;
	protected String exceptionMessage;
	protected Map<String, String> validationErrorMap;

	public BaseForm() {
		super();
	}

	public Map<String, String> getValidationErrorMap() {
		return validationErrorMap;
	}

	public void setValidationErrorMap(Map<String, String> validationErrorMap) {
		this.validationErrorMap = validationErrorMap;
	}

	public boolean isError() {
		return error;
	}

	public void handleException(Exception exception) {
		StringWriter sw = new StringWriter();
		exception.printStackTrace(new PrintWriter(sw));
		setExceptionMessage(StringEscapeUtils.escapeJavaScript(sw.toString()));
		setError(true);
	}

	public void setError(boolean error) {
		this.error = error;
	}

	public String getExceptionMessage() {
		return exceptionMessage;
	}

	public void setExceptionMessage(String exceptionMessage) {
		this.exceptionMessage = exceptionMessage;
	}

}